#include<bits/stdc++.h>
using namespace std;
int n, T, ans;
int a[20], c[20];
void dfs(int step){
    if(step > n){
        int rdl = -1, bel = -1, sum = 0;
        for(int i = 1; i <= n; i++){
            if(c[i] == 0) sum += (a[i] == rdl ? rdl : 0), rdl = a[i];
            else sum += (a[i] == bel ? bel : 0), bel = a[i];
        }
        ans = max(ans, sum);
        return;
    }
    c[step] = 0;
    dfs(step+1);
    c[step] = 1;
    dfs(step+1);
}
void solve(){
    cin >> n;
    ans = -1;
    for(int i = 1; i <= n; i++) cin >> a[i];
    dfs(1);
    cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while(T--) solve();
    return 0;
}